# In our example, we draw six lines. The lines are drawn in six different pen styles. There are five predefined pen
# styles. We can create also custom pen styles. The last line is drawn using custom pen style.
# QtGui.QPen is an elementary graphics object. It is used to draw lines, curves and outlines of rectangles, ellipses,
# polygons or other shapes.

import sys, random
from PySide import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        super(Window, self).__init__()

    # Drawing is done within a paintEvent
    def paintEvent(self, event):
        # QtGui.QPainter class is responsible for all the low level painting. All the painting event go between begin()
        # and the end() methods. The actual painting in this program is delegated to the 'drawText' method
        painter = QtGui.QPainter()
        painter.begin(self)
        self.drawLines(event, painter)
        painter.end()

        self.setGeometry(200, 200, 280, 300)
        self.setWindowTitle("Drawing-Pen styles")

    def drawLines(self, event, painter):
        pen = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine)
        painter.setPen(pen)
        painter.drawLine(20, 40, 250, 40)

        pen.setStyle(QtCore.Qt.DashLine)
        painter.setPen(pen)
        painter.drawLine(20, 80, 250, 80)

        pen.setStyle(QtCore.Qt.DashDotLine)
        painter.setPen(pen)
        painter.drawLine(20, 120, 250, 120)

        pen.setStyle(QtCore.Qt.DotLine)
        painter.setPen(pen)
        painter.drawLine(20, 160, 250, 160)

        pen.setStyle(QtCore.Qt.DashDotDotLine)
        painter.setPen(pen)
        painter.drawLine(20, 200, 250, 200)

        # Here we define a custom pen style. We set a QtCore.Qt.CustomDashLine pen style and call a setDashPattern()
        # method. The list of numbers defines a style. There must be an even number of numbers. Odd numbers define a
        # dash, even numbers space. The greater the number, the greater the space or the dash. Our pattern is 1px dash
        # 4px space 5px dash 4px space etc.
        pen.setStyle(QtCore.Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        painter.setPen(pen)
        painter.drawLine(20, 240, 250, 240)


if __name__ == "__main__":
    appObject = QtGui.QApplication(sys.argv)
    ex = Window()
    ex.show()
    sys.exit(appObject.exec_())

